package com.weishi.project.training.controller;

import java.util.List;

import io.swagger.annotations.Api;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.weishi.framework.aspectj.lang.annotation.Log;
import com.weishi.framework.aspectj.lang.enums.BusinessType;
import java.util.Arrays;
import com.weishi.project.training.domain.AnnualProject;
import com.weishi.project.training.service.IAnnualProjectService;
import com.weishi.framework.web.controller.BaseController;
import com.weishi.framework.web.domain.AjaxResult;
import com.weishi.common.utils.poi.ExcelUtil;
import com.weishi.framework.web.page.TableDataInfo;

/**
 * annualProjectController
 */
@Api(value = "年度训练项目",description = "年度训练项目")
@RestController
@RequestMapping("/training/annualProject")
public class AnnualProjectController extends BaseController {

    @Autowired
    private IAnnualProjectService annualProjectService;

    /**
     * 查询年度训练项目列表
     */
    @PreAuthorize("@ss.hasPermi('training:annualProject:list')")
    @GetMapping("/list")
    public TableDataInfo list(AnnualProject annualProject) {
        startPage();
        List<AnnualProject> list = annualProjectService.selectAnnualProjectList(annualProject);
        return getDataTable(list);
    }

    /**
     * 导出年度训练项目列表
     */
    @PreAuthorize("@ss.hasPermi('training:annualProject:export')")
    @Log(title = "annualProject", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AnnualProject annualProject) {
        List<AnnualProject> list = annualProjectService.selectAnnualProjectList(annualProject);
        ExcelUtil<AnnualProject> util = new ExcelUtil<AnnualProject>(AnnualProject.class);
        return util.exportExcel(list, "annualProject");
    }

    /**
     * 获取年度训练项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('training:annualProject:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return AjaxResult.success(annualProjectService.getById(id));
    }

    /**
     * 新增年度训练项目
     */
    @PreAuthorize("@ss.hasPermi('training:annualProject:add')")
    @Log(title = "annualProject", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody List<AnnualProject> annualProject) {
        annualProject.forEach( p->{
            annualProjectService.save(p);
        });
        return AjaxResult.success();
    }

    /**
     * 修改年度训练项目
     */
    @PreAuthorize("@ss.hasPermi('training:annualProject:edit')")
    @Log(title = "annualProject", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody List<AnnualProject> annualProject) {
        annualProject.forEach( p->{
            annualProjectService.saveOrUpdate(p);
        });
        return AjaxResult.success();
    }

    /**
     * 删除年度训练项目
     */
    @PreAuthorize("@ss.hasPermi('training:annualProject:remove')")
    @Log(title = "annualProject", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        annualProjectService.removeByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }
    
}